<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<div id="viewExamGrid"></div>
<div id="viewExamToolbar">
	<div>
		<a href="#" class="easyui-linkbutton" onclick="viewExam.toolbar.startExam();" data-options="
		iconCls:'icon-edit',
		plain:true">
		进去考试
		</a>
	</div>
</div>

<script>	
	var viewExam = {
		init : function() {
			viewExam.viewExamGrid = $('#viewExamGrid');
			viewExam.viewExamGrid.datagrid({
			    url: '<%=request.getContextPath()%>/StuServlet?command=listStu',
			    fitColumns: true,
			    striped: true,
			    rownumbers: true,
			    pagination: true,
			    pageSize: 10,
			    pageList: [10, 20, 30, 40, 50],
			    pageNumber: 1,
			    toolbar: '#viewExamToolbar',
			    columns:[[
					{field:'value1', width:100, checkbox: true},
					{field:'exam_time_start', title:'考试时间（起）', width:100, align:'center'},
					{field:'exam_time_stop', title:'考试时间（止）', width:100, align:'center'},
					{field:'exam_classroom', title:'考试教室', width:100, align:'center'},
					{field:'pagename', title:'试卷名称', width:100, align:'center'},
					{field:'username', title:'操作者', width:100, align:'center'},
					{field:'operate_time', title:'操作时间', width:100, align:'center'}
			    ]],
				onDblClickRow: function(rowIndex, rowData) {
					viewExam.toolbar.showUpdateDialog(rowData.id);
				}
			});
		},
		toolbar: {
			redo: function() {
				viewExam.viewExamGrid.datagrid('unselectAll');
			},
			startExam:function(){
				var row = viewExam.viewExamGrid.datagrid('getSelections');
				if(row.length==1){
					$.post('<%=request.getContextPath()%>/exam/PaperServlet?command=getPaper', {examPlanId:row[0].id}, function(data) {
						if (data) {
							$('#examPaperName').text(data.name);
							$('#examCourse').text(data.courseName);
							$('#examType').text(data.paperType);
							$('#examTotal').text(data.totalPoint);
							$('#examTime').text(data.totalMinutes);
							$('#examTime').append('<input type="hidden" name="questionNumber" value="'+(data.singleOptionNumber + data.multiOptionNumber + data.judgeNumber)+'">');
							$('#examTotal').append('<input type="hidden" name="passPoint" value="'+ data.passPoint +'">');
							for (var i=0;i < data.singleOptionNumber;i++){
								$('#single').append('<li><strong>'+ data.questionList[i].question +'</strong><br></li>');
								$('#single').append('<input type="radio" name="question'+ i +'" value="A">A:  '+data.questionList[i].answerA +'<br>');
								$('#single').append('<input type="radio" name="question'+ i +'" value="B">B:  '+data.questionList[i].answerB +'<br>');
								$('#single').append('<input type="radio" name="question'+ i +'" value="C">C:  '+data.questionList[i].answerC +'<br>');
								$('#single').append('<input type="radio" name="question'+ i +'" value="D">D:  '+data.questionList[i].answerD +'<br>');
								$('#single').append('<input type="hidden" name="questionId'+ i +'" value="'+data.questionList[i].id+'">');
								
							}
							for (var i=data.singleOptionNumber;i < data.singleOptionNumber+data.multiOptionNumber;i++){
								$('#multi').append('<li><strong>'+ data.questionList[i].question +'</strong><br></li>');
								$('#multi').append('<input type="checkbox" name="question'+ i +'" value="A">A:  '+data.questionList[i].answerA +'<br>');
								$('#multi').append('<input type="checkbox" name="question'+ i +'" value="B">B:  '+data.questionList[i].answerB +'<br>');
								$('#multi').append('<input type="checkbox" name="question'+ i +'" value="C">C:  '+data.questionList[i].answerC +'<br>');
								$('#multi').append('<input type="checkbox" name="question'+ i +'" value="D">D:  '+data.questionList[i].answerD +'<br>');
								$('#multi').append('<input type="hidden" name="questionId'+ i +'" value="'+data.questionList[i].id+'">');
								
							}
							for (var i=data.singleOptionNumber+data.multiOptionNumber;i < data.singleOptionNumber+data.multiOptionNumber+data.judgeNumber;i++){
								$('#judge').append('<li><strong>'+ data.questionList[i].question +'</strong><br></li>');
								$('#judge').append('<input type="radio" name="question'+ i +'" value="A">  '+data.questionList[i].answerA +'<br>');
								$('#judge').append('<input type="radio" name="question'+ i +'" value="B">  '+data.questionList[i].answerB +'<br>');
								$('#judge').append('<input type="hidden" name="questionId'+ i +'" value="'+data.questionList[i].id+'">');
							}
						}
						$('#examDialog').dialog('open');
					},'json');
				}else{
					$.messager.show({
						title: '系统提示',
						msg: '请选择一条考试安排进入考试！',
						timeout: 3000,
						showType: 'slide'
					});	
				}
				
			}
		}
	};

	$(function(){
		viewExam.init();
	});
</script>